home *** CD-ROM | disk | FTP | other *** search
- /*
- WDEF Draw.c
-
- */
-
- #include <Color.h>
- #include <FontMgr.h>
- #include <MacTypes.h>
- #include <MemoryMgr.h>
- #include <OSUtil.h>
- #include <Quickdraw.h>
- #include <ToolboxUtil.h>
- #include <WindowMgr.h>
- #include <Global.h>
-
- typedef struct {
- Rect stdState, userState;
- Boolean buttonState;
- } WSDRecord, *WSDPointer, **WSDHandle;
-
- #define buttonState (**(WSDHandle)(*(WindowPeek)window).dataHandle).buttonState
-
- #define plain 0 /* used to set a text face to plain text */
- #define blackHex 0xFFFFFFFF
- #define gray1Hex 0x55AA55AA
- #define gray2Hex 0xAA55AA55
- #define whiteHex 0x00000000
-
- typedef struct {
- long black[2], white[2], gray[2];
- RGBColor cwhite, clight, cgray, cdark, cblack, chilite, ctext;
- } patsRec, *patsPtr;
-
- RGBColor PackGray(brightness)
- int brightness;
- {
- RGBColor gray;
-
- gray.red = gray.green = gray.blue = brightness;
- return gray;
- }
-
- /*╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
- drawing my window
- ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤*/
- drawMyWindow( var, window, param )
- short var; /* variation code on this type window */
- WindowPtr window; /* pointer to the window */
- long param; /* parameter used for many things */
- {
- SysEnvRec thisWorld;
- OSErr err;
- GrafPtr wport, portSave;
- Boolean hasColorQD;
-
- PenState savedPen;
- PixPatHandle pnPatSave, bkPatSave, fillPatSave;
- RGBColor pnClrSave, bkClrSave;
- RgnHandle clipSave, tempRgn;
-
- patsRec patstor;
- patsPtr pat;
-
- Rect windowRect;
- GDHandle gdh;
- CTabHandle colors;
-
- if ( !(*(WindowPeek)window).visible ) return;
-
- pat = &patstor;
-
- err = SysEnvirons( 1, &thisWorld ); /* assess if we have a color comp */
- if (err != noErr) hasColorQD = false;
- else hasColorQD = thisWorld.hasColorQD;
-
- if (hasColorQD) {
- GetPort(&portSave);
- GetCWMgrPort(&wport);
- SetPort(wport);
-
- pnPatSave = NewPixPat();
- bkPatSave = NewPixPat();
- fillPatSave = NewPixPat();
-
- CopyPixPat(((CGrafPtr)wport)->pnPixPat, pnPatSave);
- CopyPixPat(((CGrafPtr)wport)->bkPixPat, bkPatSave);
- CopyPixPat(((CGrafPtr)wport)->fillPixPat, fillPatSave);
- GetForeColor(&pnClrSave);
- GetBackColor(&bkClrSave);
-
- pat->cblack = PackGray(0);
- pat->cdark = PackGray(0x4000);
- pat->cgray = PackGray(0x8000);
- pat->clight = PackGray(0xc000);
- pat->cwhite = PackGray(0xffff);
-
- if ((window->portBits.rowBytes & (3<<14)) == 0xc000) {
- GetAuxWin(window, &colors);
- pat->chilite = (**(GrafVars**)((CGrafPtr)window)->grafVars)
- .rgbHiliteColor;
- pat->ctext = (**colors).ctTable[2].rgb;
- } else {
- pat->chilite = pat->cgray;
- pat->ctext = pat->cblack;
- }
- }
-
- clipSave = NewRgn();
- tempRgn = NewRgn();
- GetClip(clipSave);
- windowRect = (**(*(WindowPeek)window).strucRgn).rgnBBox;
-
- if ( Abs(windowRect.left % 2) == Abs(windowRect.top % 2) )
- pat->gray[0] = pat->gray[1] = gray1Hex;
- else
- pat->gray[0] = pat->gray[1] = gray2Hex;
-
- pat->black[0] = pat->black[1] = blackHex;
- pat->white[0] = pat->white[1] = whiteHex;
- GetPenState( &savedPen );
-
- if (hasColorQD) {
- gdh = GetDeviceList();
- do {
- if (TestDeviceAttribute(gdh, 13) && TestDeviceAttribute(gdh, 15)) {
- HLock(gdh);
- if (RectInRgn(&(**gdh).gdRect, clipSave)) {
- RectRgn( tempRgn, &(**gdh).gdRect );
- SectRgn(clipSave, tempRgn, tempRgn);
- SetClip(tempRgn);
- if ((**(**gdh).gdPMap).cmpSize >= 4)
- drawonce(param, var, window, windowRect,
- pat, true);
- else
- drawonce(param, var, window, windowRect,
- pat, false);
- }
- HUnlock(gdh);
- }
- } while ((gdh = GetNextDevice(gdh)) != nil);
- } else
- drawonce(param, var, window, windowRect, pat, false);
-
- SetClip(clipSave);
- DisposeRgn(clipSave);
- DisposeRgn(tempRgn);
-
- SetPenState(&savedPen);
- if (hasColorQD) {
- RGBForeColor(&pnClrSave);
- RGBBackColor(&bkClrSave);
-
- CopyPixPat(pnPatSave, ((CGrafPtr)wport)->pnPixPat);
- CopyPixPat(bkPatSave, ((CGrafPtr)wport)->bkPixPat);
- CopyPixPat(fillPatSave, ((CGrafPtr)wport)->fillPixPat);
- DisposPixPat(pnPatSave);
- DisposPixPat(bkPatSave);
- DisposPixPat(fillPatSave);
-
- SetPort(portSave);
- }
-
- } /* end of drawMyWindow() */
-
- DrawPane(pat, thisRect, invert, drawColor)
- patsPtr pat;
- Rect thisRect;
- Boolean invert;
- Boolean drawColor;
- {
- /* fill the area with white */
- if (invert)
- PenPat( &pat->black );
- else
- PenPat( &pat->white );
- PaintRect( &thisRect );
- /* add the bottom shadow */
- PenSize( 1, 1 );
- if (drawColor) {
- PenPat( &pat->black );
- if (invert)
- RGBForeColor(&pat->cdark);
- else
- RGBForeColor(&pat->clight);
- } else {
- if (invert)
- PenPat(&pat->black);
- else
- PenPat(&pat->white);
- }
- MoveTo(thisRect.left+1, thisRect.bottom-1);
- LineTo(thisRect.right-1, thisRect.bottom-1);
- LineTo(thisRect.right-1, thisRect.top+1);
- /* add the top shadow */
- if (drawColor) {
- PenPat( &pat->black );
- if (invert)
- RGBForeColor(&pat->clight);
- else
- RGBForeColor(&pat->cdark);
- } else {
- if (invert)
- PenPat(&pat->white);
- else
- PenPat(&pat->black);
- }
- MoveTo( thisRect.left, thisRect.bottom-1 );
- LineTo( thisRect.left, thisRect.top );
- LineTo( thisRect.right-1, thisRect.top );
- }
-
- drawWindowTitle( window, titleRect, pat, hilited, drawColor )
- WindowPtr window;
- Rect *titleRect;
- patsPtr pat;
- Boolean hilited, drawColor;
- {
- short savedFont;
- short savedSize;
- Style savedFace;
- Str255 windowTitle;
- short titleWidth;
- RgnHandle oldClip, newClip;
- GrafPtr aPort;
-
- GetPort(&aPort);
- savedFont = aPort->txFont;
- savedSize = aPort->txSize;
- savedFace = aPort->txFace;
-
- TextFont( 3 ); /* set geneva */
- TextSize( 9 ); /* and small */
- TextFace( plain ); /* and plain or italic */
-
- GetWTitle( window, windowTitle );
-
- titleWidth = StringWidth( windowTitle );
-
- if ( titleWidth > 0 ) {
-
- titleWidth += 12; /* enough for edges */
-
- if ( ( (*titleRect).right - (*titleRect).left ) > titleWidth )
- (*titleRect).right = (*titleRect).left + titleWidth;
-
- if (hilited) DrawPane(pat, *titleRect, false, drawColor);
-
- /* now shrink the box & set the clip region in case of a long title */
- oldClip = NewRgn();
- newClip = NewRgn();
- GetClip( oldClip );
-
- InsetRect( titleRect, 1, 1 );
- RectRgn( newClip, titleRect );
- SectRgn( oldClip, newClip, newClip );
- SetClip( newClip );
-
- /* now position ourselves & draw the title */
- PenPat(&pat->black);
- if (drawColor) {
- if (hilited)
- RGBForeColor(&pat->ctext);
- else
- RGBForeColor(&pat->cwhite);
- }
-
- MoveTo( (*titleRect).left + 5, (*titleRect).bottom - 2 );
- DrawString( windowTitle );
-
- SetClip( oldClip );
- DisposeRgn( oldClip );
- DisposeRgn( newClip );
-
- } /* enough of a title to go with */
-
- TextFont(savedFont);
- TextSize(savedSize);
- TextFace(savedFace);
- }
-
- ToggleGoaway(frame, pat, hilite, drawColor)
- Rect frame;
- patsPtr pat;
- Boolean hilite;
- Boolean drawColor;
- {
- DrawPane(pat, frame, hilite, drawColor);
- InsetRect(&frame, 2, 2);
- PenPat(&pat->black);
-
- if (hilite) {
- if (drawColor)
- RGBForeColor(&pat->chilite);
- else
- PenPat(&pat->white);
- } else {
- if (drawColor)
- RGBForeColor(&pat->cblack);
- }
- PaintOval(&frame);
- }
-
- ToggleZoom(frame, pat, hilite, drawColor)
- Rect frame;
- patsPtr pat;
- Boolean hilite;
- Boolean drawColor;
- {
- DrawPane(pat, frame, hilite, drawColor);
- InsetRect(&frame, 2, 2);
- --frame.right; --frame.bottom;
- PenPat(&pat->black);
-
- if (hilite) {
- if (drawColor)
- RGBForeColor(&pat->chilite);
- else
- PenPat(&pat->white);
- } else {
- if (drawColor)
- RGBForeColor(&pat->cblack);
- }
- PaintRect(&frame);
- }
-
- DrawFrame(pat, frame, width, drawColor)
- patsPtr pat;
- Rect frame;
- int width;
- Boolean drawColor;
- {
- frame.right -= 2;
- frame.bottom -= 2;
-
- PenSize(width, width);
- if (drawColor)
- RGBForeColor(&pat->clight);
- else
- PenPat( &pat->white );
- FrameRect(&frame);
-
- OffsetRect(&frame, 2, 2);
- if (drawColor)
- RGBForeColor(&pat->cdark);
- else
- PenPat( &pat->black );
- FrameRect(&frame);
-
- OffsetRect(&frame, -1, -1);
- if (drawColor)
- RGBForeColor(&pat->cgray);
- else
- PenPat( &pat->gray );
- FrameRect( &frame );
- }
-
- drawonce( param, var, window, windowRect, pat, drawColor)
- long param;
- short var;
- WindowPtr window;
- Rect windowRect;
- patsPtr pat;
- Boolean drawColor;
- {
- Rect thisRect;
-
- switch ( (short)param ) {
- case ( 0 ):
-
- thisRect = windowRect;
-
- PenNormal();
-
- /* ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤ now for the more specific parts */
- switch ( var ) {
- case ( documentProc ): /* a regular window */
- case ( documentProc + 8): /* a zooming window */
- case ( noGrowDocProc ): /* a regular window with no growing */
- DrawFrame(pat, thisRect, 2, drawColor);
- InsetRect(&thisRect, 1,1);
-
- thisRect.bottom = thisRect.top + 19;
- PenPat(&pat->black);
- if (drawColor)
- RGBForeColor(&pat->cgray);
- else
- PenPat( &pat->gray );
- PaintRect( &thisRect );
- PenPat( &pat->black );
- if (drawColor)
- RGBForeColor(&pat->cdark);
- PenSize( 1, 1 );
- MoveTo( windowRect.left+3, windowRect.top+19 );
- LineTo( windowRect.right-4, windowRect.top+19 );
-
- if ( (*(WindowPeek)window).hilited ) {
- /* ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤ the goaway box */
- if ( (*(WindowPeek)window).goAwayFlag ) {
- SetRect( &thisRect,
- windowRect.left + 3,
- windowRect.top + 3,
- windowRect.left + 17,
- windowRect.top + 17
- );
- DrawPane(pat, thisRect, false, drawColor);
- /* add the symbol */
- ToggleGoaway(thisRect, pat, false, drawColor);
- }
- /* ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤ the zoom box */
- if ( (*(WindowPeek)window).spareFlag ) {
- SetRect( &thisRect,
- windowRect.right - 17,
- windowRect.top + 3,
- windowRect.right - 3,
- windowRect.top + 17
- );
- DrawPane(pat, thisRect, false, drawColor);
- /* add the symbol */
- ToggleZoom(thisRect, pat, false, drawColor);
- }
- /* ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤ the title */
- SetRect( &thisRect,
- windowRect.left + 19,
- windowRect.top + 3,
- windowRect.right - 19,
- windowRect.top + 17
- );
- PenSize( 1, 1 );
- if ( thisRect.right - thisRect.left > 0 )
- drawWindowTitle( window, &thisRect, pat, true, drawColor );
- } else {
- /* ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤ the blank title bar */
- if (!drawColor) {
- thisRect.top += 2;
- thisRect.left += 2;
- thisRect.bottom = thisRect.top + 14;
- thisRect.right -=2;
- DrawPane(pat, thisRect, false, drawColor);
- }
- /* ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤ the title */
- SetRect( &thisRect,
- windowRect.left + 19,
- windowRect.top + 3,
- windowRect.right - 19,
- windowRect.top + 17
- );
- drawWindowTitle( window, &thisRect, pat, false, drawColor );
- }
- break;
-
- case ( dBoxProc ): /* dialog box variation */
- DrawFrame(pat, thisRect, 4, drawColor);
- thisRect.right -= 2;
- thisRect.bottom -= 2;
- OffsetRect(&thisRect, 1, 1);
- InsetRect( &thisRect, 5, 5 );
- PenSize( 2, 2 );
- if (drawColor) {
- PenPat(&pat->black);
- RGBForeColor(&pat->clight);
- } else
- PenPat( &pat->white );
- FrameRect( &thisRect );
- break;
- case ( plainDBox ): /* plain box variation */
- FrameRect( &thisRect );
- break;
- case ( altDBoxProc ): /* shadow box variation */
- thisRect.right -= 2;
- thisRect.bottom -= 2;
- FrameRect( &thisRect );
- PenSize( 2, 2 );
- if (drawColor)
- RGBForeColor(&pat->cgray);
- MoveTo( thisRect.left + 2, thisRect.bottom );
- LineTo( thisRect.right, thisRect.bottom );
- LineTo( thisRect.right, thisRect.top + 2 );
- break;
- }
-
- break;
-
- case ( wInGoAway ):
-
- SetRect( &thisRect, /* just toggle the goAway */
- windowRect.left + 3,
- windowRect.top + 3,
- windowRect.left + 17,
- windowRect.top + 17
- );
- buttonState = !buttonState;
- if (drawColor)
- ToggleGoaway(thisRect, pat, buttonState, drawColor);
- else
- InvertRect(&thisRect);
-
- break;
-
- case ( wInZoomIn ):
- case ( wInZoomOut ):
-
- SetRect( &thisRect, /* just toggle the zoomBox */
- windowRect.right - 17,
- windowRect.top + 3,
- windowRect.right - 3,
- windowRect.top + 17
- );
- buttonState = !buttonState;
- if (drawColor)
- ToggleZoom(thisRect, pat, buttonState, drawColor);
- else
- InvertRect(&thisRect);
-
- break;
-
- default:
- break;
-
- }
- }
-